package com.ruoyi.kong.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.kong.entity.KongCertificate;
import com.ruoyi.kong.entity.KongEntity;
import com.ruoyi.kong.service.IKongCertificateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.cert.Certificate;

@RestController
@RequestMapping("/kong/certificate")
public class KongCertificateController extends BaseController {

    @Autowired
    private IKongCertificateService kongCertificateService;

    @GetMapping("/list")
    public TableDataInfo getCertificates(){
        startPage();
        KongEntity<KongCertificate> certificates = kongCertificateService.certificates();
        return getDataTable(certificates.getData());
    }

    @PostMapping("/add")
    public AjaxResult addCertificate(@RequestBody  KongCertificate certificate){
        KongCertificate kongCertificate = kongCertificateService.addCertificate(certificate);
        return AjaxResult.success(kongCertificate);
    }

    @PostMapping("/delete/{id}")
    public AjaxResult deleteCertificate(@PathVariable String id){
        kongCertificateService.deleteCertificate(id);
        return  success();
    }

    @PostMapping("/update/{id}")
    public AjaxResult updateCertificate(@PathVariable String id, @RequestBody KongCertificate certificate){
        KongCertificate kongCertificate = kongCertificateService.updateCertificate(id, certificate);
        return AjaxResult.success(kongCertificate);
    }

}
